using System;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace CSW.Framework.Common.Exceptions
{
    /// <summary>
    /// Database query exception.
    /// </summary>
    [Serializable]
    public class DatabaseQueryException : Exception
    {
        private readonly string m_CommandText;
        private readonly IEnumerable<SqlParameter> m_Parameters;

        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseQueryException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="parameters">The parameters.</param>
        public DatabaseQueryException(string message, string commandText, IEnumerable<SqlParameter> parameters)
            : base(message)
        {
            m_CommandText = commandText;
            m_Parameters = parameters;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseQueryException"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="innerException">The inner exception.</param>
        public DatabaseQueryException(string message, string commandText, IEnumerable<SqlParameter> parameters, Exception innerException)
            : base(message, innerException)
        {
            m_CommandText = commandText;
            m_Parameters = parameters;
        }

        /// <summary>
        /// Gets the command text.
        /// </summary>
        /// <value>The command text.</value>
        public string CommandText
        {
            get { return m_CommandText; }
        }

        /// <summary>
        /// Gets the parameters.
        /// </summary>
        /// <value>The parameters.</value>
        public IEnumerable<SqlParameter> Parameters
        {
            get { return m_Parameters; }
        }
    }
}